﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OtherUtils  {

  

    public static bool ArrayContains<T>(T[] array,T t)
    {
        for(int i =0;i< array.Length; i++)
        {
            if (array[i].Equals( t))
                return true;
        }
        return false;
    }
  

    /// <summary>
    /// 比较版本大小（如 1.02.01与1.02.00）
    /// </summary>
    /// <param name="v0"></param>
    /// <param name="v1"></param>
    /// <returns>1：v0大，-1：v1大，0：一样大</returns>
    public static int CompareVersions(string v0, string v1)
    {
        string[] tempV = v0.Split('.');
        List<int> v0_List = new List<int>();
        foreach (var item in tempV)
        {
            v0_List.Add(int.Parse(item));
        }

        string[] tempV1 = v1.Split('.');
        List<int> v1_List = new List<int>();
        foreach (var item in tempV1)
        {
            v1_List.Add(int.Parse(item));
        }

        int shotLenth;
        if (v0_List.Count == v1_List.Count)
        {
            shotLenth = v1_List.Count;
        }
        else
        {
            if (v0_List.Count > v1_List.Count)
                shotLenth = v1_List.Count;
            else
                shotLenth = v0_List.Count;
        }

        for (int i = 0; i < shotLenth; i++)
        {
            if (v0_List[i] == v1_List[i])
                continue;
            if (v0_List[i] > v1_List[i])
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }

        if (v0_List.Count == v1_List.Count)
        {
            return 0;
        }
        else
        {

            if (v0_List.Count > v1_List.Count)
            {
                for (int i = v1_List.Count - 1; i < v0_List.Count; i++)
                {
                    if (v0_List[i] != 0)
                        return 1;
                }

                return 0;
            }

            else
            {
                for (int i = v0_List.Count - 1; i < v1_List.Count; i++)
                {
                    if (v1_List[i] != 0)
                        return -1;
                }

                return 0;
            }
        }

    }
}
